package com.hummingbird.portal.mapper;

import com.hummingbird.portal.pojo.Permission;
import com.hummingbird.portal.pojo.Role;
import com.hummingbird.portal.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hummingbird.portal.vo.UserVO;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* <p>
    *  Mapper 接口
    * </p>
*
* @author -1E18
* @since 2024-09-22
*/
@Repository
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user where username = #{name}")
    User findUserByUsername(String name);

    @Select("select" +
            " p.id , p.name" +
            " from user u" +
            " left join user_role ur on u.id=ur.user_id" +
            " left join role r on r.id=ur.role_id" +
            " left join role_permission rp on r.id=rp.role_id" +
            " left join permission p on p.id=rp.permission_id" + " where u.id=#{userid}")
    List<Permission> findUserPermissionsById(Integer userid);

    @Select("select id, username, nickname from user where username = #{username}")
    UserVO findUserVOByUsername(String username);

    @Select("select r.id, r.name from user u left join user_role ur on u.id = ur.user_id left join role r on r.id = ur.role_id where u.id = #{id}")
    List<Role> findUserRoleById(Integer id);
}

